package com.beerq.model;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.Serializable;

/**
 * 作者：minj on 2017/10/18 10:30
 * 用户的信息
 */
public class UserInfo implements Serializable {


    public int getAppUserId() {
        return appUserId;
    }

    public void setAppUserId(int appUserId) {
        this.appUserId = appUserId;
    }

    private int appUserId;
    private String userName;
    private String phoneNo;
    private String headPic;
    private String wxNo;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPhoneNo() {
        return phoneNo;
    }

    public void setPhoneNo(String phoneNo) {
        this.phoneNo = phoneNo;
    }

    public String getHeadPic() {
        return headPic;
    }

    public void setHeadPic(String headPic) {
        this.headPic = headPic;
    }

    public String getWxNo() {
        return wxNo;
    }

    public void setWxNo(String wxNo) {
        this.wxNo = wxNo;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    private int sex;//1是男 0是女
    private String city;
    private String province;

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    private String country;

    public static UserInfo parseUserinfo(String info){
        JSONObject jsonObject= JSON.parseObject(info);
        UserInfo userInfo=new UserInfo();
        userInfo.setPhoneNo(jsonObject.getString("MobileNo"));
        userInfo.setHeadPic(jsonObject.getString("HeadPic"));
        userInfo.setWxNo(jsonObject.getString("openid"));
        userInfo.setUserName(jsonObject.getString("UserName"));
        userInfo.setAppUserId(jsonObject.getIntValue("AppUserId"));

        if(userInfo.getUserName().equals(userInfo.getPhoneNo())){
            String phoneNo=userInfo.getPhoneNo();
            userInfo.setUserName(phoneNo.substring(0,3)+"****"+phoneNo.substring(7,11));
        }

        return userInfo;
    }
//
    public static UserInfo parseUserinfoFromWeChat(String info){

        JSONObject jsonObject= JSON.parseObject(info);
        UserInfo userInfo=new UserInfo();
        userInfo.setHeadPic(jsonObject.getString("headimgurl"));
        userInfo.setWxNo(jsonObject.getString("openid"));
        userInfo.setUserName(jsonObject.getString("nickname"));
        userInfo.setSex(jsonObject.getIntValue("sex"));
        userInfo.setProvince(jsonObject.getString("province"));
        userInfo.setCity(jsonObject.getString("city"));
        userInfo.setCountry(jsonObject.getString("country"));
        return userInfo;
    }




}
